package com.cl.blog.web.client;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cl.blog.annotation.Login;
import com.cl.blog.common.Const;
import com.cl.blog.common.Result;
import com.cl.blog.entity.BContent;
import com.cl.blog.service.BContentService;
import com.cl.blog.util.JwtUtil;
import com.cl.blog.vo.ContentSearchVo;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.jsonwebtoken.Claims;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author 付
 * @Date 2024-03-17 14:04
 * @Version 1.0
 * @description 后台管理对于文章的操作
 * @since 1.0
 */

@RestController
@RequestMapping("/user/content")
public class ContentController {

	@Autowired
	BContentService bContentService;
	@Autowired
	JwtUtil jwtUtil;

	@GetMapping("/type")
	@Login
	public Result getContentByType(Integer id) {
		List<BContent> list = bContentService.list(new QueryWrapper<BContent>()
				.eq("status", 2)
				.eq(id != 0, "type_id", id)
				.eq("is_delete", 0)
		);

		return Result.success(list);
	}

	@GetMapping("/publish")
	@Login
	public Result publishedContent(Integer status, HttpServletRequest request) {
		Object list = bContentService.getPublished(request, status);

		return Result.success(list);

	}

	/**
	 * 用户关注列表
	 *
	 * @param request
	 * @return
	 */
	@GetMapping("/collect")
	public Result getCollect(HttpServletRequest request) {
		Object list = bContentService.getCollect(request);
		return Result.success(list);
	}

	@GetMapping("/like")
	public Result getLike(HttpServletRequest request) {
		Object list = bContentService.getLike(request);
		return Result.success(list);
	}

	@PostMapping("/search")
	public Result search(@RequestBody ContentSearchVo searchVo, HttpServletRequest request) {
		System.out.println("搜索条件-->" + searchVo);
		Object obj = bContentService.selectSearch(searchVo, request);
		return Result.success(obj);
	}

	/**
	 * 获取统计数据
	 *
	 * @return
	 */
	@GetMapping("/statistics")
	public Result statistics() throws JsonProcessingException {
		Object obj = bContentService.statistics();
		return Result.success(obj);
	}

	@GetMapping("/month")
	public Result getMonthByYear(String year) throws JsonProcessingException {
		Object obj = bContentService.getMonthByYear(year);
		return Result.success(obj);
	}
}
